package com.ziiwee.reduce.describe.register;

import com.ziiwee.reduce.commons.utils.ExportUtil;
import com.ziiwee.reduce.describe.ControllerDescribe;
import com.ziiwee.reduce.describe.creators.controllers.ResourceServiceControllerDescribeCreator;
import com.ziiwee.reduce.rest.ResourceService;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
 * @author ziiwee
 * @date 2020/8/13
 */
public class DefaultResourceServiceDescribeRegister implements ResourceServiceDescribeRegister {
    private final int order;

    private final Set<ControllerDescribe> set = new HashSet<>();

    public DefaultResourceServiceDescribeRegister(int order) {
        this.order = order;
    }

    @Override
    public void register(ResourceService<?, ?> service) {
        if (ExportUtil.isExport(service.getClass())) {
            set.add(new ResourceServiceControllerDescribeCreator(service).create());
        }
    }

    @Override
    public int getOrder() {
        return order;
    }

    @Override
    public Collection<ControllerDescribe> getDescribes() {
        return set;
    }
}
